package JDBC;

import javax.swing.plaf.nimbus.State;
import java.sql.*;

public class JDBCDemo5 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true","root","root");
        Statement state = conn.createStatement();
        String sql="SELECT id,name,age,salary,title " +
                   "FROM teacher";
        ResultSet rs = state.executeQuery(sql);
        while (rs.next()){
            int id = rs.getInt("id");
            String name = rs.getString("name");
            int age = rs.getInt("age");
            int salary = rs.getInt("salary");
            String title = rs.getString("title");
            System.out.println("id:"+id+" name:"+name+" age"+age+" salary:"+salary+" title:"+title);
        }
        conn.close();
    }
}
